package admin

import (
	"github.com/gin-gonic/gin"
	"jwgin/model/mysql"
	"jwgin/service"
)

type rabcweb struct {
}

func (l *rabcweb) Routers(Router *gin.RouterGroup) (R gin.IRoutes) {
	Router.GET("route/web", l.get)
	Router.PUT("route/web", l.put)
	Router.POST("route/web", l.post)
	Router.DELETE("route/web", l.del)
	return R
}

//获取路由
func (rabcweb) get(c *gin.Context) {
	ret := []mysql.PermissionWeb{}
	service.G.Model(mysql.PermissionWeb{}).Where("web_pid = 0 ").Find(&ret)
	for k, v := range ret {
		item := []mysql.PermissionWeb{}
		service.G.Model(mysql.PermissionWeb{}).Where("web_pid = ? ", v.WebId).Find(&item)
		ret[k].PermissionWeb = item
	}
	RespSucc(c, ret)
}
func (rabcweb) put(c *gin.Context) {
	requ := &mysql.PermissionWeb{}
	if err := c.ShouldBind(requ); err != nil {
		RespErr(c, err)
		return
	}
	requ.WebId = 0
	service.G.Create(requ)
	RespSucc(c, nil)
}
func (rabcweb) post(c *gin.Context) {
	requ := &mysql.PermissionWeb{}
	if err := c.ShouldBind(requ); err != nil {
		RespErr(c, err)
		return
	}
	service.G.Where("web_id = ?", requ.WebId).Updates(requ)
	RespSucc(c, nil)
}
func (rabcweb) del(c *gin.Context) {}
